package recursion;

public class RecursionBinarySearch {
    public static void main(String[] args) {
        int[] a = {1, 2, 4, 10, 11, 22, 44, 32, 45, 67, 87};
        int target = RecursionBinarySearch.reCursionBinarySearch(a, 4, 0, a.length);
        System.out.println(target);
    }

    public static int reCursionBinarySearch(int[] a, int target, int i, int j) {
        int m = (i + j) >>> 1;
        if (a[m] == target) return m;
        if (a[m] < target) return reCursionBinarySearch(a, target, m + 1, a.length);
        if (a[m] > target) return reCursionBinarySearch(a, target, i, m - 1);
        return -1;
    }
}
